﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuanLy_NhaSach
{
    public partial class Themsach : Form
    {
        public Themsach()
        {
            InitializeComponent();
        }

        private void sachBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.sachBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.nhaSachDataSet);
            }

        private void Themsach_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'nhaSachDataSet.NhaXuatBan' table. You can move, or remove it, as needed.
            //this.nhaXuatBanTableAdapter.Fill(this.nhaSachDataSet.NhaXuatBan);
            loaiSachBindingSource1.DataSource = NhaSachBUS.LoaiSachBUS.LoadLoaiSach();
            sachBindingSource.DataSource = NhaSachBUS.SachBUS.LoadSach();
            nhaXuatBanBindingSource.DataSource = NhaSachBUS.NhaXuatBanBUS.LoadNXB();

        }


        private void xoasach_Click(object sender, EventArgs e)
        {
            {
                NhaSachBUS.SachBUS.Xoasach(int.Parse( maSachTextBox.Text));
                sachBindingSource.DataSource = NhaSachBUS.SachBUS.LoadSach();
            }

        }

        private void tabPage2_Click(object sender, EventArgs e)
        {

        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void them_Click(object sender, EventArgs e)
        {
            try
            {
                NhaSachBUS.SachBUS.ThemSach(Int64.Parse(txtmasach.Text), maLoaiTextBox1.Text, txttensach.Text, txttacgia.Text, int.Parse(txtsoluong.Text), tenNXBComboBox.Text, txtdonvitinh.Text, int.Parse(txtdongia.Text), int.Parse(txtsoluongton.Text));
                sachBindingSource.DataSource = NhaSachBUS.SachBUS.LoadSach();
            }
            catch
            { }
        }

        private void capnhat_Click(object sender, EventArgs e)
        {
            try
            {
                NhaSachBUS.SachBUS.CapNhatSach(Int64.Parse(maSachTextBox.Text), maLoaiTextBox.Text, tenSachTextBox.Text, tacGiaTextBox.Text, int.Parse(soLuongTextBox.Text), tenNXBComboBox.Text, donViTinhTextBox.Text, int.Parse(donGiaTextBox.Text), int.Parse(soLuongTonTextBox.Text));
                sachBindingSource.DataSource = NhaSachBUS.SachBUS.LoadSach();
            }
            catch
            {
            }
        }

        private void thoatthemsach(object sender, EventArgs e)
        {
            CloseForm();
        }
        public void CloseForm()
        {
            this.Dispose();
        }


    }
}
